<?php

class commandHandler {

  private static  $modlist = array (1=>"Module1", "Module2", "Module3", "Module4","Module5");
  private static  $DEFAULT_MODULE = 'Index';

  public function __construct() {
  }

  public function doRequest() {
   // choosing language
   $language= strtok($_SERVER['HTTP_ACCEPT_LANGUAGE'], ';');

   // Managing URI parameters
   
   list($module, $action, $id) = split('/', $_SERVER['QUERY_STRING']);
   if (isset($id)) $_REQUEST['id']=$id;
   // Old fashion : module & action as parameters in the query string
   // $controllerName = ( (!(isset($_REQUEST['mod'])) || !(array_search($_REQUEST['mod'],self::$modlist))) ? self::$DEFAULT_MODULE : $_REQUEST['mod']);
  //$actionToCall =  ( (!(isset($_REQUEST['action']) )) ? 'default' : $_REQUEST['action']);


   $controllerName = ( (!(isset($module)) || !(array_search($module,self::$modlist))) ? self::$DEFAULT_MODULE : $module);
   $controllerClassName = $controllerName.'Controller';

   $actionToCall =  ( (!(isset($action) )) ? 'default' : $action);
   $actionToCall = strtolower(trim($actionToCall));
   $controller = new $controllerClassName($actionToCall, $language) ;
   $controller->callAction();
  }

}

?>
